﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using IBatisNet.DataMapper;
using MyBatis.Data.Model;

namespace MyBatis.Data.Dao
{
	/// <summary>
	/// CustomersDao
	/// </summary>
	public class CustomersDao : MyBatisDaoBase<Customers>
	{
		
		#region 构造函数
		public CustomersDao()
			: base("NorthwindReader.config", "NorthwindWriter.config")
		{

		}
		public CustomersDao(string read, string writer) : base(read, writer) { }
		#endregion

		#region 方法
		/// <summary>
		/// 获取Customers
		/// </summary>
		/// <param name="customerID">CustomerID</param>
		/// <returns>Customers</returns>
		public Customers GetCustomers(string customerID)
		{
			return Reader.QueryForObject<Customers>(GetStatementName("GetCustomers"), customerID);
		}

		
		/// <summary>
		/// 获取Customers
		/// </summary>
		/// <param name="customerID">CustomerID</param>
		/// <returns>Customers</returns>
		public Customers GetCustomersByTopicId(string customerID)
		{
			return Reader.QueryForObject<Customers>(GetStatementName("GetCustomersByTopicId"), customerID);
		}

		/// <summary>
		/// 获取Customers集合
		/// </summary>
		/// <param name="customersQp">Customers</param>
		/// <returns>Customers集合</returns>
		public IList<Customers> GetCustomerss(CustomersQP customersQp)
		{
			if(customersQp.IsReset)
            {
                customersQp.PageIndex = 1;
            }
			customersQp.ItemCount = GetCustomerssCount(customersQp);
            // string runSQL = this.GetRunSql("GetCustomerss", customersQp);    // 获取生成的SQL语句
			return Reader.QueryForList<Customers>(GetStatementName("GetCustomerss"), customersQp);
		}		
		
		/// <summary>
		/// 获取Customers 记录数
		/// </summary>
		/// <param name="customersQp">query</param>
		/// <returns>Customers集合</returns>
		public int GetCustomerssCount(CustomersQP customersQp)
		{
			return Reader.QueryForObject<int>(GetStatementName("GetCustomerssCount"), customersQp);
		}

		/// <summary>
		/// 有否Customers
		/// </summary>
		/// <param name="customerID">CustomerID</param>
		/// <returns>结果</returns>
		public bool HasCustomers(string customerID)
		{
			return Reader.QueryForObject<int>(GetStatementName("HasCustomers"), customerID) > 0;
		}

		/// <summary>
		/// 获取Customers指定字段的值
		/// </summary>
		/// <param name="dict">查询参数</param>
		/// <returns>结果</returns>
		public string GetCustomersFieldValue(HybridDictionary dict)
		{
			return Reader.QueryForObject<string>(GetStatementName("GetCustomersFieldValue"), dict);
		}

		/// <summary>
		/// 插入Customers
		/// </summary>
		/// <param name="customers">Customers</param>
		/// <returns>结果</returns>
		public int InsertCustomers(CustomersQP customersQp)
		{
			var rst = Writer.Insert(GetStatementName("InsertCustomers"), customersQp);
			return (int)(rst??0);
		}
	
		/// <summary>
		/// 更新Customers
		/// </summary>
		/// <param name="customersQp">Customers</param>
		/// <returns>结果</returns>
		public bool UpdateCustomers(CustomersQP customersQp)
		{
			return Writer.Update(GetStatementName("UpdateCustomers"), customersQp) > 0;
		}		
	
		/// <summary>
		/// 更新Customers
		/// </summary>
		/// <param name="customersQp">Customers</param>
		/// <returns>结果</returns>
		public bool UpdateCustomersByTopicId(CustomersQP customersQp)
		{
			return Writer.Update(GetStatementName("UpdateCustomersByTopicId"), customersQp) > 0;
		}

		///<summary>
		///删除Customers
		///</summary>
		///<param name="customerID">CustomerID</param>
		///<returns>结果</returns>
		public bool RemoveCustomers(string customerID)
		{
			return Writer.Delete(GetStatementName("RemoveCustomers"), customerID) > 0;
		}

		///<summary>
		///删除Customers
		///</summary>
		///<param name="customerID">CustomerID</param>
		///<returns>结果</returns>
		public bool RemoveCustomersByTopicId(string customerID)
		{
			return Writer.Delete(GetStatementName("RemoveCustomersByTopicId"), customerID) > 0;
		}
		#endregion
	}
}

